package util;

/**
 * @author ‘洋毛’
 * @version 1.0
 * @description: TODO
 * @date 2021/12/11 14:26
 */
public class ResultEntity<T> {

    // 封装当前请求的处理结果是成功还是失败
    private Integer code;

    // 设置两个常量
    private static final Integer SUCCESS = 0;
    private static final Integer FAILED = 416;

    // 请求错误时，返回的错误信息，对应SUCCESS和FAILED
    private String msg;

    private Integer count;

    // 要返回的数据
    private T data;



    public ResultEntity() {
    }

    public ResultEntity(String msg, Integer count, T data, Integer code) {
        this.msg = msg;
        this.count = count;
        this.data = data;
        this.code = code;
    }

    public static <Type> ResultEntity<Type> successWithoutData() {
        return new ResultEntity<Type>(null,0,null,SUCCESS);
    }

    public static <Type> ResultEntity<Type> successWithData(Type data, Integer count) {
        return new ResultEntity<Type>(null,count,data,SUCCESS);
    }

    public static <Type> ResultEntity<Type> failed(String message) {
        return new ResultEntity<Type>(message,0,null,FAILED);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "ResultEntity{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", count=" + count +
                ", data=" + data +
                '}';
    }
}
